var headerH;
apiready = function() {
  //  Commodity_management1();
  // Commodity_management();
  // getpassword();
  // setToken();
  //  getToken();
  //  return
    var header = $api.byId('wrap'); // 获取 header 标签元素
    headerH = $api.fixStatusBar(header);
    fnNVTabBar_open();
    fnOpenMessageFrame("home", "widget://html/home/index_b.html")

};
//底部切换
function fnNVTabBar_open() {
    var NVTabBar = api.require('NVTabBar');
    NVTabBar.open({
        styles: {
            bg: '#fff',
            h: 49,
            dividingLine: {
                width: 0,
                color: '#000'
            },
            badge: {
                bgColor: '#fff',
                numColor: '#fff',
                size: 6.0,
                centerX: 40,
                centerY: 6
            }
        },
        items: [{
            w: api.winWidth / 5.0,
            bg: {
                marginB: 0
            },
            iconRect: {
                w: 25.0,
                h: 25.0,
            },
            icon: {
                normal: 'widget://image/home.png',
                selected: 'widget://image/homeA.png'
            },
            title: {
                text: '首页',
                size: 12.0,
                normal: '#4D4D4D',
                selected: '#FF9900',
                marginB: 3.0
            }
        }, {
            w: api.winWidth / 5.0,
            bg: {
                marginB: 0
            },
            iconRect: {
                w: 25.0,
                h: 25.0,
            },
            icon: {
                normal: 'widget://image/video.png',
                selected: 'widget://image/videoA.png'
            },
            title: {
                text: '视频',
                size: 12.0,
                normal: '#4D4D4D',
                selected: '#FF9900',
                marginB: 3.0
            }
        }, {
            w: api.winWidth / 5.0,
            bg: {
                marginB: 7
            },
            iconRect: {
                w: 45,
                h: 45,
            },
            icon: {
                normal: 'widget://image/hongbao.png',
                selected: 'widget://image/hongbao.png'
            },
            title: {
                text: '抢红包',
                size: 12.0,
                normal: '#4D4D4D',
                selected: '#FF9900',
                marginB: 3.0
            }
        }, {
            w: api.winWidth / 5.0,
            bg: {
                marginB: 0
            },
            iconRect: {
                w: 25.0,
                h: 25.0,
            },
            icon: {
                normal: 'widget://image/fabu.png',
                selected: 'widget://image/fabuA.png'
            },
            title: {
                text: '发布',
                size: 12.0,
                normal: '#4D4D4D',
                selected: '#FF9900',
                marginB: 3.0
            }
        }, {
            w: api.winWidth / 5.0,
            bg: {
                marginB: 0
            },
            iconRect: {
                w: 25.0,
                h: 25.0,
            },
            icon: {
                normal: 'widget://image/me.png',
                selected: 'widget://image/meA.png'
            },
            title: {
                text: '我的',
                size: 12.0,
                normal: '#4D4D4D',
                selected: '#FF9900',
                marginB: 3.0
            }
        }],
        selectedIndex: 0
    }, function(ret, err) {

        NVTabBar.bringToFront();
        if (0 == ret.index) {
            name = 'home';
            url = 'widget://html/home/index_b.html';
            fnOpenMessageFrame(name, url)
        } else if (1 == ret.index) {
            name = 'classify';
            url = 'widget://html/video/index.html';
            fnOpenMessageFrame(name, url)
        } else if (2 == ret.index) {
            name = 'vip';
            url = 'widget://html/rob/index.html';
            fnOpenMessageFrame(name, url)
        } else if (3 == ret.index) {
            name = 'message';
            url = 'widget://html/Release/index.html';
            fnOpenMessageFrame(name, url)
        } else if (4 == ret.index) {
            name = 'own';
            url = 'widget://html/center/index.html';
            fnOpenMessageFrame(name, url)
        }
    });
}


//打开Frame
function fnOpenMessageFrame(name, url) {
    api.openFrame({
        name: name,
        url: url,
        rect: {
            x: 0,
            y: headerH,
            w: 'auto',
            marginBottom: 48
        },
        bounces: false,
        bgColor: 'rgba(255,255,255,1)',
        vScrollBarEnabled: true,
    });
}

// 登录
function getToken(){
  var token = $api.getStorage('token');
  if (!token) {

      api.openWin({
          name: 'login',
          url: 'widget://html/login/login.html',
          bgColor: 'rgba(255,255,255,1)',
          rect: {
              x: 0,
              y: 0,
              w: 'auto',
              h: 'auto'
          }
      });
      return false;
  }
}

// 注册
function setToken(){
  var token1 = $api.getStorage('token');
  if (!token1) {

      api.openWin({
          name: 'register',
          url: 'widget://html/login/register.html',
          bgColor: 'rgba(255,255,255,1)',
          rect: {
              x: 0,
              y: 0,
              w: 'auto',
              h: 'auto'
          }
      });
      return false;
  }
}

// 找回密码
function getpassword(){
  var token2 = $api.getStorage('token');
  if (!token2) {

      api.openWin({
          name: 'password',
          url: 'widget://html/login/password.html',
          bgColor: 'rgba(255,255,255,1)',
          rect: {
              x: 0,
              y: 0,
              w: 'auto',
              h: 'auto'
          }
      });
      return false;
  }
}

// 我的商品管理(什么都没有)
function Commodity_management(){
  var token2 = $api.getStorage('token');
  if (!token2) {

      api.openWin({
          name: 'Commodity_management',
          url: 'widget://html/goods/Commodity_management.html',
          bgColor: 'rgba(255,255,255,1)',
          rect: {
              x: 0,
              y: 0,
              w: 'auto',
              h: 'auto'
          }
      });
      return false;
  }
}

// 我的商品管理(断网)
function Commodity_management1(){
  var token3 = $api.getStorage('token');
  if (!token3) {

      api.openWin({
          name: 'Commodity_management1',
          url: 'widget://html/goods/Commodity_management1.html',
          bgColor: 'rgba(255,255,255,1)',
          rect: {
              x: 0,
              y: 0,
              w: 'auto',
              h: 'auto'
          }
      });
      return false;
  }
}





function setStatusStyle(flag) {
    if (flag) {
        api.setStatusBarStyle({
            style: 'dark'
        });
    } else {
        api.setStatusBarStyle({
            style: 'light'
        });
    }
}
